package com.jackson.engineeringtechnologyguide.conditional;

/*
 * Author: JacksonCoder
 * FileName: ConditionalConfig
 * Version: 1.0.0
 * Date: 2025/1/11
 */


import com.jackson.engineeringtechnologyguide.conditional.condition.RandBooleanCondition;
import com.jackson.engineeringtechnologyguide.conditional.condition.RandIntegerCondition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

import java.util.Random;

/**
 * 随机数生成器条件配置
 */
@Configuration
public class ConditionalConfig {

    @Bean
    @Conditional(RandBooleanCondition.class)
    public RandomDataSupplier<Boolean> randBooleanComponent() {
        return new RandomDataSupplier<>(() -> {
            Random random = new Random();
            return random.nextBoolean();
        });
    }

    @Bean
    @Conditional(RandIntegerCondition.class)
    public RandomDataSupplier<Integer> randIntegerComponent() {
        return new RandomDataSupplier<>(() -> {
            Random random = new Random();
            return random.nextInt(1024);
        });
    }

}
